<!--********************************************************************
* Copyright© 2000 - 2025 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title data-i18n="resources.title_vectorDataEvent"></title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
            width: 100%;
            height: 100%
        }

        #map {
            position: absolute;
            width: 100%;
            height: 100%;
        }

        #toolbar {
            position: absolute;
            top: 50px;
            right: 10px;
            text-align: center;
            z-index: 100;
            border-radius: 4px;
        }
    </style>
</head>
<body>
<div id="toolbar" class="panel panel-primary">
    <div class='panel-heading'>
        <h5 class='panel-title text-center' data-i18n="resources.title_vectorDataEvent"></h5></div>
    <div class='panel-body content'>
        <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_addData" onclick="addData()"/>
    </div>
</div>
<div id="map"></div>
<script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
<script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
<script>
    var map, layer, vectorlayer, pointFeature,
        host = window.isLocal ? window.server : "https://iserver.supermap.io",
        url = host + "/iserver/services/map-world/rest/maps/World";

    init();

    function init() {
        map = new SuperMap.Map("map", {
            controls: [
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation(),
            ]
        });
        map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
        layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, null, {maxResolution: "auto"});
        layer.events.on({"layerInitialized": addLayer});
        vectorlayer = new SuperMap.Layer.Vector("vectorLayer");
        var callbacks = {
            click: function (currentFeature) {
                closeInfoWin();
                var popup = new SuperMap.Popup.FramedCloud("popwin",
                    new SuperMap.LonLat(0, 0),
                    null,
                    resources.text_mouseClickEventLayer,
                    null,
                    true);
                infowin = popup;
                map.addPopup(popup);
            }
        };
        var selectFeature = new SuperMap.Control.SelectFeature(vectorlayer,
            {
                callbacks: callbacks
            });
        map.addControl(selectFeature);
        selectFeature.activate();

    }

    function addLayer() {

        map.addLayers([layer, vectorlayer]);
        //显示地图范围
        map.setCenter(new SuperMap.LonLat(0, 0), 0);
    }

    var infowin = null;

    function closeInfoWin() {
        if (infowin) {
            try {
                infowin.hide();
                infowin.destroy();
            }
            catch (e) {
            }
        }
    }

    function addData() {

        vectorlayer.removeAllFeatures();
        var point = new SuperMap.Geometry.Point(0, 0);
        pointFeature = new SuperMap.Feature.Vector(point);
        pointFeature.style = {
            fillColor: "red",
            strokeColor: "yellow",
            pointRadius: 7
        };
        vectorlayer.addFeatures(pointFeature);
    }
</script>

</body>
</html>